<template>
  <div>
    setup
  </div>
</template>

<script>
  import {} from "@vue/composition-api";

  export default {
    setup(props, ctx) {
      console.log("setup");
      /**1. setup执行时机在beforeCreate之后created之前
       beforeCreate
       setup
       created
       */

      console.log("props:", props);

      /** 3. 由于是函数,访问不到this,故vue2里this上的vue特性的其它东西我们需要通过ctx参数来访问*/
      console.log("ctx:", ctx);
      /*
        context: {slots: {…}, …}
        root: Vue
        parent: VueComponent
        refs: Object
        attrs: Object
        listeners: Object
        isServer: false
        ssrContext: undefined
        emit: ƒ ()
        slots: {}
      */
    },
    beforeCreate() {
      console.log("beforeCreate");
    },
    created() {
      console.log("created");
    },
    /** 2. ↓必须要声明才能在setup里的props里拿到*/
    props: {
      p1: String
    }
  };
</script>

<style lang="scss" scoped></style>
